using System;
using Avanzis.QueryFramework;
using NUnit.Framework;

namespace Avanzis.QueryBuilder.Nunit
{

    [TestFixture]
    public class DeleteBuilderTests
    {
        [TestFixtureSetUp]
        public void Setup()
        {
            QueryFrameworkConfiguration.Dialect = Dialects.MSSql2005Dialect;
            QueryBuilder.QueryProcessor.ResetProcessor();
        }

        [Test]
        public void SimpleDeleteTest()
        {
            DeleteBuilder deleteBuilder = new DeleteBuilder("Customers");
            deleteBuilder.Where.Filters.Add("CustomerId", SqlOperator.Equals, 1);

            string sql = "DELETE \nFROM [Customers]\nWHERE (CustomerId = 1)\n";
            Assert.AreEqual(sql, deleteBuilder.ToString());
        }

        [Test]        
        [ExpectedException(typeof(ArgumentNullException))]
        public void DeleteAllProtectionEnabledTest()
        {
            DeleteBuilder deleteBuilder = new DeleteBuilder("Customers");
            string sql = "DELETE \nFROM [Customers]\n";
            Assert.AreEqual(sql, deleteBuilder.ToString());
        }

        [Test]        
        public void DeleteAllProtectionDisabledTest()
        {
            DeleteBuilder deleteBuilder = new DeleteBuilder("Customers");
            deleteBuilder.AllowDeleteAll = true;
            string sql = "DELETE \nFROM [Customers]\n";
            Assert.AreEqual(sql, deleteBuilder.ToString());
        }
    }
}
